import {findStockId, listItems} from "../service/item"

export default {
    namespaced: true,
    state: {
        item: {},
        items: [],
        dialogVisible: false,
        searchParams: {type: "", value: ""},
        pagination: {},
        //查看详情框状态
        selectItemVisible: false,
        //添加框
        addItemVisible: false,
        //图片信息
        dialogImageUrl: '',
        base64: '',
    },
    mutations: {
        setItem(state, item) {
            state.item = item;
        },
        setItems(state, items) {
            state.items = items;
        },
        //设置图片信息
        setDialogImageUrl(state, dialogImageUrl) {
            state.dialogImageUrl = dialogImageUrl
        },
        setBase64(state, base64) {
            state.base64 = base64
        },

        setSearchParams(state, searchParams) {
            state.searchParams = searchParams;
        },
        //查询页显示
        setselectItemVisible(state, selectItemVisible) {
            state.selectItemVisible = selectItemVisible
        },
        //查询页显示
        setAddItemVisible(state, addItemVisible) {
            state.addItemVisible = addItemVisible
        },
        //分页
        setPagination(state, pagination) {
            state.pagination = pagination;
        }
    },
    actions: {
        async listItems({commit, state}, params = {}) {
            if (!params.size && state.pagination.size) {
                params.size = state.pagination.size;
            }
            params.type = state.searchParams.type;
            params.value = state.searchParams.value;
            let response = await listItems(params);
            console.log(response)
            commit("setItems", response.data.data);
            commit("setPagination", response.data);
            console.log(3333333)
        },
        async findByItem(context, stockId) {
            // console.log(this.state.item.items[stockId])
            let response = await findStockId(stockId);
            context.commit("setItem", response.data);
        },


    }
};